package com.buyantech.smweb.dao;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;
import cn.org.rapid_framework.page.Page;
import com.buyantech.smweb.model.Suggestion;
import com.buyantech.smweb.vo.query.SuggestionQuery;

@Repository
public class SuggestionDao extends BaseHibernateDao<Suggestion,java.lang.String>{

	@Override
	public Class getEntityClass() {
		return Suggestion.class;
	}
	
	public Page findPage(SuggestionQuery query) {
		String sql = "select t from Suggestion t where 1=1 "
				+ "/~ and t.id = {id} ~/"
			  	+ "/~ and t.userid = {userid} ~/"
			  	+ "/~ and t.username = {username} ~/"
			  	+ "/~ and t.title = {title} ~/"
			  	+ "/~ and t.content = {content} ~/"
				+ "/~ order by [sortColumns] ~/";

        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
		return pageQuery(sql,query);
	}

	public Page searchPage(SuggestionQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from Suggestion t where 1=1 "
			  	+ "/~ and t.id like '%[id]%' ~/"
			  	+ "/~ and t.userid like '%[userid]%' ~/"
			  	+ "/~ and t.username like '%[username]%' ~/"
			  	+ "/~ and t.title like '%[title]%' ~/"
			  	+ "/~ and t.content like '%[content]%' ~/"
				+ "/~ order by [sortColumns] ~/";
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
		return pageQuery(sql,query);
	}
 
}
